//
//  YCRegisterSuccessViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/7.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  注册成功

#import "YCRegisterSuccessViewController.h"
#import "YCRegisterImproveViewController.h"


@interface YCRegisterSuccessViewController ()
/** scrollView  */
@property (nonatomic, strong) UIScrollView *scrollView;
/** contentView  */
@property (nonatomic, strong) UIView *contentView;

///名字
@property (nonatomic,readonly) UILabel *usernameLabel;
///注册成功
@property (nonatomic,readonly) UILabel *registerSuccessLabel;

///下一步按钮
@property (nonatomic,readonly) UIButton *nextButton;

@property (nonatomic, strong) YCLoginUser *userModel;

@end

@implementation YCRegisterSuccessViewController

@synthesize usernameLabel = _usernameLabel;
@synthesize registerSuccessLabel = _registerSuccessLabel;
@synthesize nextButton = _nextButton;

// 用户名字
- (UILabel *)usernameLabel
{
    if(!_usernameLabel)
    {
        _usernameLabel = [[UILabel alloc] init];
        _usernameLabel.text = @"张行";
        _usernameLabel.textColor = [UIColor yc_colorWithUInt:0x3d3e40];
        _usernameLabel.textAlignment = NSTextAlignmentCenter;
        _usernameLabel.font = [UIFont systemFontOfSize:19];
    }
    return _usernameLabel;
}

// 注册成功
- (UILabel *)registerSuccessLabel
{
    if(!_registerSuccessLabel)
    {
        _registerSuccessLabel = [[UILabel alloc] init];
        _registerSuccessLabel.text = @"注册成功";
        _registerSuccessLabel.textColor = [UIColor yc_colorWithUInt:0x3d3e40];
        _registerSuccessLabel.textAlignment = NSTextAlignmentCenter;
        _registerSuccessLabel.font = [UIFont systemFontOfSize:36];
    }
    return _registerSuccessLabel;
}

// 下一步
- (UIButton *)nextButton
{
    if(!_nextButton)
    {
        _nextButton = [[UIButton alloc] init];
        _nextButton.titleLabel.font = [UIFont boldSystemFontOfSize:15];
        [_nextButton setTitleColor:[UIColor yc_colorWithUInt:0x3d3e40] forState:UIControlStateNormal];
        _nextButton.backgroundColor = [UIColor yc_colorWithUInt:0xf8bb36];
        _nextButton.layer.cornerRadius = 17.5;
        [_nextButton setTitle:NSLocalizedString(@"下一步", nil) forState:UIControlStateNormal];
        [_nextButton addTarget:self action:@selector(didTouchUpInsideNextButton:) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _nextButton;
}

#pragma mark - 生命周期

- (instancetype)initWithUserModel:(YCLoginUser *)user
{
    if (self = [super init]) {
        _userModel = user;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self yc_addBackBarButtonItem];
    self.view.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    [self makeView];
    self.usernameLabel.text = self.userModel.userNickname;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)makeView
{
    self.scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    self.scrollView.alwaysBounceVertical = YES;
    
    [self.view addSubview:self.scrollView];
    self.scrollView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.view);
    }];
    
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    self.contentView = contentView;
    [self.scrollView addSubview:contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.scrollView);
        make.width.equalTo(self.scrollView);
    }];
    
    [self.contentView addSubview:self.registerSuccessLabel];
    [self.contentView addSubview:self.usernameLabel];
    [self.contentView addSubview:self.nextButton];
    
    [_usernameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(heightFromIphone6Height(192));
        make.centerX.equalTo(self.contentView);
    }];
    
    [_registerSuccessLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_usernameLabel.mas_bottom).offset(heightFromIphone6Height(25));
        make.centerX.equalTo(self.contentView);
    }];
    
    [_nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_registerSuccessLabel.mas_bottom).with.offset(heightFromIphone6Height(195));
        make.centerX.equalTo(self.contentView);
        make.left.equalTo(self.contentView).offset(47);
        make.right.equalTo(self.contentView).offset(-47);
        make.height.equalTo(@36);
    }];
    
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        [YCAdapter performOtherBlock:^{
            make.bottom.equalTo(_nextButton.mas_bottom).offset(90);
        } IPhone6Block:^{
            make.bottom.equalTo(_nextButton.mas_bottom).offset(163);
        } IPhone6pBlock:^{
            make.bottom.equalTo(_nextButton.mas_bottom).offset(170);
        }];
    }];
    
    [self.view layoutIfNeeded];
    self.scrollView.contentSize = CGSizeMake(0, CGRectGetMaxY(self.contentView.frame)-20);
}


#pragma mark -- 响应事件

///下一步
- (void)didTouchUpInsideNextButton:(UIButton *)button
{
    YCLog(@"下一步");
    UIViewController *improveVc= [[YCRegisterImproveViewController alloc] initWithUserModel:self.userModel];
    [self.navigationController pushViewController:improveVc animated:YES];
    
}




@end
